######################################
#
######################################
#source file
SOURCE  := $(wildcard *.c) $(wildcard *.cpp)
OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))

#target you can change test to what you want

TARGET  := main


#compile and lib parameter

CC      := gcc
CXX     := g++
LIBS    :=
LDFLAGS := -lblas -llapacke -lgfortran
DEFINES :=
INCLUDE := -I src
CFLAGS  := -g -Wall -O3 $(DEFINES) $(INCLUDE)
CXXFLAGS:= $(CFLAGS) -std=c++14 


#i think you should do anything here

.PHONY : everything objs clean veryclean rebuild
all:
	$(CXX) $(CXXFLAGS) -o main main.cpp $(LDFLAGS)
	./main
run:
	$(CXX) $(CXXFLAGS) -o main main.cpp $(LDFLAGS)
	./main
	@cd Output/ && matlab -nodesktop -nosplash -r B_complete
	@cd Output/ && matlab -nodesktop -nosplash -r B_notAknot
	@cd Output/ && matlab -nodesktop -nosplash -r C_Bspline1
	@cd Output/ && matlab -nodesktop -nosplash -r C_Bspline2
	@cd Output/ && matlab -nodesktop -nosplash -r E_heart
	@cd Output/ && matlab -nodesktop -nosplash -r F_spline
	@cd Output/ && matlab -nodesktop -nosplash -r G_table1
	@cd Output/ && matlab -nodesktop -nosplash -r G_table2

everything : $(TARGET)

objs : $(OBJS)

rebuild: veryclean everything

clean :
	rm -fr *.so
	rm -fr *.o
	rm -fr *.log *.aux *.pdf
	rm -fr $(TARGET)

main:
	$(CXX) $(CXXFLAGS) -o $@ main.cpp $(LDFLAGS)
testall:
	@echo ----------------------------Test for Vec---------------------------------
	@cd test/ && make testvec
	@cd test/ && ./testvec
	@echo ----------------------------Test for Polynomial---------------------------------
	@cd test/ && make testpoly
	@cd test/ && ./testpoly
	@echo ----------------------------Test for spline of ppform---------------------------------
	@cd test/ && make testspline
	@cd test/ && ./testspline
	@echo ----------------------------Test for B-spline---------------------------------
	@cd test/ && make testBspline
	@cd test/ && ./testBspline
	@echo ----------------------------Test for spline of Bform---------------------------------
	@cd test/ && make testBFormspline
	@cd test/ && ./testBFormspline
	@echo ----------------------------Test for knots-helper---------------------------------
	@cd test/ && make testKnotsHelper
	@cd test/ && ./testKnotsHelper
	@echo ----------------------------Test for spline of cardinalB---------------------------------
	@cd test/ && make testCardinalBspline
	@cd test/ && ./testCardinalBspline
	@echo Use "make cleantest" to clean all executable test.
cleantest:
	@cd test/ && make clean
doc:
	xelatex doc.tex
	xelatex doc.tex
